package CommonGui;

import java.awt.Component;
import java.awt.ComponentOrientation;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableCellRenderer;

public class MultiLineCellRenderer extends JTextArea implements
		TableCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MultiLineCellRenderer() {
		setLineWrap(true);
		setWrapStyleWord(true);
		setOpaque(true);
		setEditable(false); // this line doesn't seem to be doing anything

	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		setAlignmentX(RIGHT_ALIGNMENT);

		if (isSelected) {
			setForeground(table.getSelectionForeground());
			setBackground(table.getSelectionBackground());
		} else {
			setForeground(table.getForeground());
			setBackground(table.getBackground());
		}
		setFont(table.getFont());
		if (hasFocus) {
			setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
			if (table.isCellEditable(row, column)) {
				setForeground(UIManager.getColor("Table.focusCellForeground"));
				setBackground(UIManager.getColor("Table.focusCellBackground"));
			}
		} else {
			setBorder(new EmptyBorder(1, 2, 1, 2));
		}

		if (column == 4) {
			if (value != null) {
				if (Integer.parseInt(value.toString()) == 0) {
					setText("סגור");
				}
				else if (Integer.parseInt(value.toString()) == 1) {
					setText("פתוח");
				}
				else if (Integer.parseInt(value.toString()) == 2) {
					setText("בוטל");
				} else
					setText("");

			} else
				setText("");

		} else {
			setText((value == null) ? "" : value.toString());
		}
		setEditable(false); // this line doesn't seem to be doing anything
		this.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

		return this;
	}

}